import { createStore } from 'vuex'
import Request from '@/utils/request'
import merchant from './modules/merchant'
export default createStore({
  state:{
    carCode:localStorage.getItem('carCode'),
    carDetail:JSON.parse(sessionStorage.getItem('carDetail'))
  },
  getters:{
    // carCode(state) {
    //   return state.carCode;
    // }
  },
  mutations:{
    set_carCode: (state, data) => {
      localStorage.setItem('carCode',data)
      state.carCode = data
    },
    set_carDetail: (state, data) => {
      sessionStorage.setItem('carDetail',JSON.stringify(data))
      state.carDetail = data
    },
  },
  actions:{
    async get_ad_list({commit}, params) { // 获取首页广告数据
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/publiciz/list',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async get_community_list({commit}, params) { // 获取小区
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/community/list',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async get_building_list({commit}, params) { // 获取楼栋
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/building/list',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async get_unit_list({commit}, params) { // 获取单元
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/unit/list',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async get_room_list({commit}, params) { // 获房间
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/room/list',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async deposit_open_door({commit}, params) { // 存件开门
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/put/open',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async out_open_door({commit}, params) { // 取件开门
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/out/open',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async verify_room({commit}, params) { // 检查房间人信息
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/room/verify',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async create_pay_order({commit}, params) { // 创建支付订单
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/create/order',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async get_wx_pay_codeimg({commit}, params) { // 获取微信支付二维码 
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/wx/toQrPay',params,{responseType: "arraybuffer",})
        .then(res=>{
          if(res && res.data){
            resolve(res.data) 
          }else{
            resolve(null)
          } 
        })
      })
    },
    async get_ali_pay_codeimg({commit}, params) { // 获取支付宝支付二维码 
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/ali/toQrPay',params,{responseType: "arraybuffer",})
        .then(res=>{
          if(res && res.data){
            resolve(res.data) 
          }else{
            resolve(null)
          }
        })
      })
    },
    async get_pay_channel({commit}, params) { // 获取支付渠道 
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/pay/channel',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async get_pay_status({commit}, params) { // 查询支付状态 
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/pay/query',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async get_car_code({commit}, params) { // 获取小车编码 
      return new Promise((resolve,reject)=>{
        Request.get('http://api.ej12366.video/MP_verify_6hZDju2fOyNbnjIf.txt',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async get_payment({commit}, params) { // 缴费类型 
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/payment/list',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
    async get_car_detail({commit}, params) { // 小车信息 
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/car/detail',params)
        .then(res=>{
          commit('set_carDetail',res.data.data)
          resolve(res.data) 
        })
      })
    },
    async get_payment_price({commit}, params) { // 获取缴费金额 
      return new Promise((resolve,reject)=>{
        Request.post('/api/h5/payment/price',params)
        .then(res=>{
          resolve(res.data) 
        })
      })
    },
  },
  modules:{
    merchant
  }
})
